package com.gsy.dto;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 基础查询类
 * @author hthuang
 * @date 2018年6月25日
 */
public class BasePageSearchDto implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 647498819871057177L;
	public static final int DEFAULT_PAGE_SIZE = 15;
	public static final int DEFAULT_PAGE_NO = 1;
	protected Integer pageNo = DEFAULT_PAGE_NO;
	protected Integer pageSize = DEFAULT_PAGE_SIZE;
	protected String orderBy;
	private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";
	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_PATTERN);

	@SuppressWarnings("static-method")
	protected Date getTime(String dateStr) {
		if (dateStr != null && dateStr.trim() != "") {
			try {
				return DATE_FORMAT.parse(dateStr);
			} catch (ParseException e) {
				//ignore
			}
		}
		return null;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public Integer getPageIndex() {
		Integer pageIndex = this.pageNo;
		return (pageIndex - 1) * this.pageSize;
	}
}
